package net.xdclass.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.xdclass.product.model.vo.BannerVO;
import net.xdclass.product.model.BannerDO;
import net.xdclass.product.mapper.BannerMapper;
import net.xdclass.product.service.BannerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yaya
 * @since 2023-12-13
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public List<BannerVO> list() {
        QueryWrapper<BannerDO> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("weight");
        List<BannerDO> bannerDOS = bannerMapper.selectList(wrapper);
        return bannerDOS.stream().map(this::toVo).collect(Collectors.toList());
    }

    private BannerVO toVo(BannerDO bannerDO){
        BannerVO vo = new BannerVO();
        if (bannerDO == null){
            return vo;
        }
        BeanUtils.copyProperties(bannerDO, vo);
        return vo;
    }
}
